import unittest
from kuai.pykuai import *
from random import random, seed
from cmath import pi

class TestXYZ(unittest.TestCase):
    TEST_NUMBER = 10
    
    def setUp(self):
        seed(None)
        
    def testDistance(self):
        for i in range(TestXYZ.TEST_NUMBER):
            v1 = XYZ(random(), random(), random())
            v2 = XYZ(random(), random(), random())
            v2 /= abs(v2)
            self.assertAlmostEqual(abs(v2), 1.0)
            r = random() * 10000
            v3 = v1 + v2 * r
            self.assertAlmostEqual(abs(v3-v1), r)
            
    def testAngle(self):
        for i in range(TestXYZ.TEST_NUMBER):
            v1 = XYZ(random(), random(), random())
            v2 = XYZ(random(), random(), random())
            v3 = v1 * v2
            self.assertAlmostEqual(angle(v1, v3), pi / 2)
            self.assertAlmostEqual(angle(v2, v3), pi / 2)
            
